package com.py.credit.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.service.AppSelectService;
import com.py.framework.core.annotation.IgnoreAuthority;

@RestController
@RequestMapping("/appSelect")
public class AppSelectController {
	@Autowired
	private AppSelectService appSelectService;
	/**
	 * 查询企业的红黑许可处罚的数量
	 * @param qymc
	 * @param tyshxydm
	 * @return
	 */
	@IgnoreAuthority
	@RequestMapping("/num.json")
	public RestServiceResult<Object> num( @RequestParam(value ="userid", defaultValue = "", required = false) String userid,String qymc,String tyshxydm) {
		RestServiceResult<Object> result = new RestServiceResult<Object>();
		try {
			result.setData(appSelectService.select(userid));
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			ExceptionLogger.error("AppSelectController#num", "查询app许可等数据异常！ERROR:" + e.getMessage(), e);
			return result;
		}
	}
	/**
	 * 查询医生护士
	 * @param type
	 * @return
	 */
	@IgnoreAuthority
	@RequestMapping("/hsyc.json")
	public RestServiceResult hsyc(String type,String name,String pageNo,String pageSize) {
		RestServiceResult result = new RestServiceResult();
		try {
			result.setData(appSelectService.selectYsHs(type, name, pageNo, pageSize));
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			ExceptionLogger.error("AppSelectController#hsyc", "查询app医生护士等数据异常！ERROR:" + e.getMessage(), e);
			return result;
		}
	}
	/**
	 * 查询经营异常名录
	 */
	@IgnoreAuthority
	@RequestMapping("/jyycml.json")
	public RestServiceResult jyycml(String name,String pageNo,String pageSize) {
		RestServiceResult result = new RestServiceResult();
		try {
			result.setData(appSelectService.selectJYYCML(name, pageNo, pageSize));
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			ExceptionLogger.error("AppSelectController#jyycml", "查询app医生护士等数据异常！ERROR:" + e.getMessage(), e);
			return result;
		}
	}
	/**
	 * 数据分析 红黑榜
	 */
	@IgnoreAuthority
	@RequestMapping("/selectHongHeiBang.json")
	public RestServiceResult selectHongHeiBang(String type) {
		RestServiceResult result = new RestServiceResult();
		try {
			if("1".equals(type)){
				result.setData(appSelectService.selectHong());
			}
			if("2".equals(type)){
				result.setData(appSelectService.selectHei());
			}
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			ExceptionLogger.error("AppSelectController#selectHongHeiBang", "查询红黑榜数据分析！ERROR:" + e.getMessage(), e);
			return result;
		}
	}
	
	@IgnoreAuthority
    @RequestMapping(value = "/addGZ.do")
    public RestServiceResult addGZ(
            @RequestParam(value ="userid", defaultValue = "", required = false) String userid,
            @RequestParam(value ="tybm", defaultValue = "", required = false) String tybm,
            @RequestParam(value ="qymc", defaultValue = "", required = false) String qymc,
            @RequestParam(value ="tyshxydm", defaultValue = "", required = false) String tyshxydm) {
		RestServiceResult result = new RestServiceResult();
		try {
			appSelectService.addGZ(userid, tybm, qymc, tyshxydm);
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			ExceptionLogger.error("AppAllController#addGZ", "app我的关注！ERROR:" + e.getMessage(), e);
			return result;
		}
    	
    	return result;
    }
	
	@IgnoreAuthority
    @RequestMapping(value = "/selectGZ.json")
    public RestServiceResult selectGZ(
            @RequestParam(value ="userid", defaultValue = "", required = false) String userid) {
		RestServiceResult result = new RestServiceResult();
		try {
			result.setData(appSelectService.selectGZ(userid));
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			ExceptionLogger.error("AppAllController#selectGZ", "app我的关注！ERROR:" + e.getMessage(), e);
			return result;
		}
    	
    	return result;
    }
	
	@IgnoreAuthority
    @RequestMapping(value = "/deleteGZ.do")
    public RestServiceResult deleteGZ(
            @RequestParam(value ="userid", defaultValue = "", required = false) String userid,
            @RequestParam(value ="tybm", defaultValue = "", required = false) String tybm) {
		RestServiceResult result = new RestServiceResult();
		try {
			appSelectService.deleteGZ(userid, tybm);
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			ExceptionLogger.error("AppAllController#deleteGZ", "app我的关注！ERROR:" + e.getMessage(), e);
			return result;
		}
    	
    	return result;
    }
	@IgnoreAuthority
    @RequestMapping(value = "/selectQYGZ.json")
    public RestServiceResult selectQYGZ(
            @RequestParam(value ="qymc", defaultValue = "", required = false) String qymc,
            @RequestParam(value ="pageNo", defaultValue = "", required = false) String pageNo,
            @RequestParam(value ="pageSize", defaultValue = "", required = false) String pageSize,
            @RequestParam(value ="userid", defaultValue = "", required = false) String userid) {
		RestServiceResult result = new RestServiceResult();
		try {
			result.setData(appSelectService.selectQYGZ(qymc, pageNo, pageSize, userid));
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			ExceptionLogger.error("AppAllController#selectQYGZ", "app查询企业信息和关注！ERROR:" + e.getMessage(), e);
			return result;
		}
    	
    	return result;
    }
}
